package controllers;

import beans.BusinessInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.impl.BusinessInformationServicesImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/business")
public class BusinessController {

    @Autowired
    private BusinessInformationServicesImpl bis;

    //0.商机管理
    @RequestMapping("/business")
    public List business() {
        List<BusinessInformation> list = bis.selectList();
        return list;
    }

    //1.创建商机
    @RequestMapping("/createbusiness")
    public String createbusiness(@RequestBody BusinessInformation businessInformation) {
        bis.insertSelective(businessInformation);
        return null;
    }

    //2.编辑商机
    @RequestMapping("/editbusiness")
    public String editbusiness(@RequestBody BusinessInformation businessInformation) {
        bis.updateByPrimaryKeySelective(businessInformation);
        return null;
    }

    //3.商机详情
    @RequestMapping("/detailsbusiness")
    public BusinessInformation detailsbusiness(HttpServletRequest request) {
        int i = Integer.parseInt(request.getParameter("organId"));
        BusinessInformation businessInformation = bis.selectByPrimaryKey(i);
        return businessInformation;
    }

    //4.商机搜索
    @RequestMapping("/searchbusiness")
    public List<BusinessInformation> searchbusiness(@RequestBody Map<String,String> request) {
        String select = request.get("selectText");
        String input = request.get("inputText");
        List<BusinessInformation> list = bis.selectSelective(select,input);
        return list;
    }

    //5.商机删除
    @RequestMapping("/deletebusiness")
    public String deletebusiness(HttpServletRequest request) {
        int i = Integer.parseInt(request.getParameter("organId"));
        bis.deleteByPrimaryKey(i);
        return null;
    }

}
